package com.auto.survey.measurecontroller

import com.auto.survey.measurecontroller.entity.InstrumentStatus

class InstrumentStatusManager (
    private val listener: MeasureProcessListener?,
    private val uiCallback: MeasureUICallback
){
    private val monitorStatus = InstrumentStatus()

    fun updateInstrumentName(name: String) {
        monitorStatus.equmentName = name
        notifyStatusUpdated()
    }

    fun updateInclineSwitch(enabled: Boolean) {
        monitorStatus.getInclineSwitch = enabled
        notifyStatusUpdated()
    }

    fun updateAngleCorrectionSwitches(
        incline: Boolean,
        standAxis: Boolean,
        collimation: Boolean,
        tiltAxis: Boolean
    ) {
        monitorStatus.inClineCorr = incline
        monitorStatus.standAxisCorr = standAxis
        monitorStatus.collimationCorr = collimation
        monitorStatus.tiltaxisCorr = tiltAxis
        notifyStatusUpdated()
    }

    fun updateInclineStatus(secT: Double, secL: Double) {
        monitorStatus.mIncline = secT < 180 && secL < 180
        notifyStatusUpdated()
    }

    fun updateMirrorType(type: String) {
        monitorStatus.mirrorType = when(type) {
            "0" -> "圆棱镜"
            "1" -> "迷你棱镜"
            "2" -> "反射片"
            else -> "未知"
        }
        notifyStatusUpdated()
    }

    fun updateMeasureMode(mode: String) {
        monitorStatus.measureMode = when(mode) {
            "0" -> "标准"
            "1" -> "快速"
            "2" -> "高精"
            "3" -> "跟踪"
            else -> "未知"
        }
        notifyStatusUpdated()
    }

    private fun notifyStatusUpdated() {
        val copy = monitorStatus.copy()
        uiCallback.onInstrumentStatusUpdated(copy)
    }
}